package com.jzwl.common.aspectj.manager;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * 防止重复提交的token切点校验方法类
 * 
 * @author xuxin
 * @version 1.0.0
 * @since 2016年4月25日16:39:34
 * */
@Aspect
@Component
public class ManagerAspectj {

	// 方法执行前调用
	// @Before("execution (* com.jzwl.system.admin.*.*.*.*(..))")
	// public void before() {
	// System.out.println("before");
	// }

	// 方法执行的前后调用
	@Around("execution (* com.jzwl.system.admin.*.*.*.*(..))")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		System.out.println("begin around");

		Object[] obj = point.getArgs();
		HttpServletRequest request = (HttpServletRequest) obj[0];
		HttpServletResponse response = (HttpServletResponse) obj[1];

		// 拦截的实体类
		Object target = point.getTarget();
		System.out.println(target.toString());
		// 拦截的方法名称
		String methodName = point.getSignature().getName();
		System.out.println(methodName);

		// 拦截的方法参数
		System.out.println(obj.toString());
		// 拦截的放参数类型
		Class[] parameterTypes = ((MethodSignature) point.getSignature())
				.getMethod().getParameterTypes();
		
		for (Class c : parameterTypes) {
			System.out.println(c.toString());
		}
		
		
		Enumeration<String> paramKeys = request.getParameterNames();
		while (paramKeys.hasMoreElements()) {
			String key = paramKeys.nextElement();
			System.out.println(key+"="+request.getParameter(key));
		}

		Object object = point.proceed();

		System.out.println("end around" + object.toString());

		return object;
	}

	// 方法执行后调用
	// @After("execution (* com.jzwl.system.admin.*.*.*.*(..))")
	// public void after() {
	// System.out.println("after");
	// }

}
